
import { hsqjInputJson, gdzczjJson } from '../data/hsqj.js';
import { saasTosj, fillInputDone } from '../../common.js';

async function fillhsqj(resData) {
  try {
    let data = saasTosj(resData, hsqjInputJson, gdzczjJson);

    console.log(data);

    let contentiframe = $('#contentiframe')[0].contentWindow;
    let iframeWindow = contentiframe.$('#mainIframe')[0].contentWindow;

    for (let key in data) {
      let value = Number.parseFloat(data[key]).toFixed(2) || '0.00';
      // let value = '12'
      if (key.includes('a105080VO.hnl')) {
        try {
          let keyArr = key.split('_');
          key = keyArr[0];
          let hc = keyArr[1];
          let ids = iframeWindow.$(`[name$="${key}"]`);
          let currentId = ids[hc];
          iframeWindow.$(currentId).val(value).trigger('change');
        } catch (e) {
          // 抵扣表不报错
        }
      } else if (iframeWindow.$(`[name$="${key}"]`).length != 0) {
        iframeWindow.$(`[name$="${key}"]`).val(value).trigger('change');
      }
    }

    fillInputDone({
      tax: 'hsqj',
      success: true,
      message: "汇算清缴-填报成功",
    })
  } catch (e) {
    console.log(e);
    fillInputDone({
      tax: 'hsqj',
      success: false,
      message: "汇算清缴-填报失败，请联系技术人员",
    })
  }


}


export {
  fillhsqj
}